package cn.zcj.studytest.config;

import cn.zcj.studytest.ThrowData.Result;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionAdvice {

    @ExceptionHandler(RuntimeException.class)
    public Result<Object> handleNotPermissionException(RuntimeException e, HttpServletRequest request) {
        String requestURI = request.getRequestURI();
        log.error("请求地址'{}',异常信息'{}'", requestURI, e.getMessage());
        return Result.fail(e.getMessage());
    }
}

